package com.vict.util;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class LocalCache {
    public static final Map<String, String> stringMap = new ConcurrentHashMap<>();
    public static final Map<String, Long> stringMapLossTimestamp = new ConcurrentHashMap<String, Long>();

    public static void setCache(String key, String value, Long losemillSeconds){
        stringMap.put(key, value);
        if(losemillSeconds != null){
            stringMapLossTimestamp.put(key, System.currentTimeMillis() + losemillSeconds);
        }
    }
    public static String getCache(String key){
        long now = System.currentTimeMillis();
        Long aLong = stringMapLossTimestamp.get(key);
        if(aLong != null && aLong <= now){
            stringMapLossTimestamp.remove(key);
            stringMap.remove(key);
            return null;
        }
        String s = stringMap.get(key);
        return s;
    }

}
